/**
 * RealtimeBoardServiceImpl.java
 * Created at 2017-12-5
 * Created by zhanghailin
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.system.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.common.service.impl.EntityServiceImpl;
import com.broadtext.common.utils.BaiduAPI;
import com.broadtext.rms.monitor.model.PackLocationInfo;
import com.broadtext.rms.system.model.RealtimeBoard;
import com.broadtext.rms.system.service.IRealtimeBoardService;

/**
 * <p>ClassName: RealtimeBoardServiceImpl</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2017-12-5</p>
 */
@Service("realtimeBoardService")
public class RealtimeBoardServiceImpl extends EntityServiceImpl<RealtimeBoard> implements IRealtimeBoardService{
    
    @Autowired
    @Qualifier("realtimeBoardDao")
    public void setEntityDao(EntityDao<RealtimeBoard> entityDao) {
        super.entityDao = entityDao;
    }
    
    @Override
    public Map<String, Object> getSocData(String packCode){
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getSocData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
    private Map<String, Object> getMapData(String sqlAlias, String packCode) throws DaoException{
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); 
        list = this.entityDao.findByProperty(sqlAlias, packCode);
        if(list!=null&&list.size()>0){
            map = list.get(0);
        }
        return map;
    }


    /** (non-Javadoc)
     * <p>Title: getVolData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getVolData(java.lang.String)
     */
    @Override
    public Map<String, Object> getVolData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getVolData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** (non-Javadoc)
     * <p>Title: getCurrentData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getCurrentData(java.lang.String)
     */
    @Override
    public Map<String, Object> getCurrentData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getCurrentData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** (non-Javadoc)
     * <p>Title: getMaxVolData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getMaxVolData(java.lang.String)
     */
    @Override
    public Map<String, Object> getMaxVolData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getMaxVolData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** (non-Javadoc)
     * <p>Title: getMinVolData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getMinVolData(java.lang.String)
     */
    @Override
    public Map<String, Object> getMinVolData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getMinVolData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** (non-Javadoc)
     * <p>Title: getMaxTempData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getMaxTempData(java.lang.String)
     */
    @Override
    public Map<String, Object> getMaxTempData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getMaxTempData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** (non-Javadoc)
     * <p>Title: getMinTempData</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getMinTempData(java.lang.String)
     */
    @Override
    public Map<String, Object> getMinTempData(String packCode) {
        try {
            return getMapData("com.broadtext.rms.system.model.RealtimeBoard.getMinTempData", packCode);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return null;
    }

    /** (non-Javadoc)
     * <p>Title: getPackCodeData</p>
     * <p>Description: </p>
     * @param params
     * @return
     * @see com.broadtext.rms.system.service.IRealtimeBoardService#getPackCodeData(java.util.Map)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Map<String, Object>> getPackCodeData(Map<String, Object> params) {
        List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.system.model.RealtimeBoard.getPackCodeData", params);
        } catch (DaoException e) {
            e.printStackTrace();
        }
        return list;
    }
    
    /**
     * 
     * <p>Description: 获取历史位置列表</p>
     * @param map 查询条件
     * @return 结果集
     * @throws DaoException 异常
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<PackLocationInfo> findHistoryLocationList(Map<String, Object> map) throws DaoException {
        List<PackLocationInfo> data;
        data = new ArrayList<PackLocationInfo>();
        List<PackLocationInfo> loList = new ArrayList<PackLocationInfo>();;
        //查询历史数据
        loList = this.entityDao.findByQuery("com.broadtext.rms.system.model.RealtimeBoard.findHistoryLocationList", map);
        if(loList != null && !loList.isEmpty()){
            //根据经纬度转换成真实地理位置
            for (int i = 0; i < loList.size(); i++) {
                if((null != loList.get(i).getLatitude() && !loList.get(i).getLatitude().trim().equals("")) && (null != loList.get(i).getLongitude()) && !loList.get(i).getLongitude().trim().equals("")){
                    //gps转百度坐标
                    double[] JWD = BaiduAPI.wgs2bd(Double.valueOf(loList.get(i).getLatitude().trim()), Double.valueOf(loList.get(i).getLongitude().trim()));
                    loList.get(i).setLatitude(String.valueOf(JWD[0]));
                    loList.get(i).setLongitude(String.valueOf(JWD[1]));
                    data.add(loList.get(i)); 
                } 
            }
        }
        return data;
    }
    

}
